package com.jlnk.androidfmc.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import java.util.Locale;

import com.jlnk.androidfmc.R;
import com.jlnk.androidfmc.entity.FootItem;

public class FootAdapter extends RecyclerView.Adapter<FootAdapter.ViewHolder> {

    private List<FootItem> itemList;

    public FootAdapter(List<FootItem> itemList) {
        this.itemList = itemList;
    }



    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_foot, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        FootItem item = itemList.get(position);
        holder.imageViewItem.setImageResource(item.getImageResourceId());
        holder.textViewName.setText(item.getName());
        holder.textViewPrice.setText(String.format("¥%.2f元/斤", item.getPrice()));

    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageViewItem;
        TextView textViewName;
        TextView textViewPrice;
        Button editButton;
        Button deleteButton;

        ViewHolder(View itemView) {
            super(itemView);
            imageViewItem = itemView.findViewById(R.id.imageViewItem);
            textViewName = itemView.findViewById(R.id.textViewName);
            textViewPrice = itemView.findViewById(R.id.textViewPrice);
            editButton = itemView.findViewById(R.id.editButton);
            deleteButton = itemView.findViewById(R.id.deleteButton);
        }
    }
}